<?php

namespace app\service;

//玩家皮肤服务层


use app\model\Skin;
use app\model\UserSkin;

class UserSkinService extends BaseService
{

    //添加玩家皮肤
    public function add_user_skin($user_id, $skin_id): array
    {
        //查询皮肤是否存在
        $skin = Skin::where("id", $skin_id)->find();
        if (!$skin) {
            return $this->returnFail("皮肤不存在");
        }

        //查询玩家是否已经拥有该角色
        $user_skin = UserSkin::where("user_id", $user_id)->where("skin_id", $skin_id)->find();
        if ($user_skin) {
            return $this->returnFail("玩家已经拥有该皮肤");
        }

        //添加玩家皮肤
        $user_skin = new UserSkin();
        $user_skin->user_id = $user_id;
        $user_skin->skin_id = $skin_id;
        $user_skin->staff_id = $skin->pid;
        $user_skin->save();

        return $this->returnSuccess("添加成功");
    }

    //查询是否拥有皮肤
    public function has_skin($user_id, $skin_id): bool
    {
        $user_skin = UserSkin::where("user_id", $user_id)->where("skin_id", $skin_id)->find();
        if ($user_skin) {
            return true;
        }
        return false;
    }




}